// 这里封装和用户相关的请求函数
import type { User, UserInfo, PatientList, Patient } from '@/types/user'
import { request } from '@/utils/request'
import type { CodeType } from '@/types/user'

export const loginByPassword = (mobile: string, password: string) => {
  return request<User>('/login/password', 'POST', {
    mobile,
    password
  })
}

// 后端是为了方便你查看验证码 直接返回了(实际开发一定不会这样)
export const getCode = (mobile: string, type: CodeType) => {
  return request<{ code: string }>('/code', 'GET', {
    mobile,
    type
  })
}

// 短信登录
export const loginByMobile = (mobile: string, code: string) =>
  request<User>('/login', 'POST', { mobile, code })

// 获取个人信息
export const getUserInfo = () => request<UserInfo>('/patient/myUser')

// 查询患者列表
export const getPatientList = () => request<PatientList>('/patient/mylist')

// 添加患者
export const addPatient = (patient: Patient) =>
  request('/patient/add', 'POST', patient)

// 编辑患者信息
export const editPatient = (patient: Patient) =>
  request('/patient/update', 'PUT', patient)

// 删除患者信息
export const delPatient = (id: string) =>
  request(`/patient/del/${id}`, 'DELETE')

// 查询患者详情
export const getPatientDetail = (id: string) =>
  request<Patient>(`/patient/info/${id}`)
